package com.tarena.lbs.basic.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.basic.dao.mapper.AreaMapper;
import com.tarena.lbs.basic.dao.repository.AreaRepository;
import com.tarena.lbs.basic.pojo.param.AreaParam;
import com.tarena.lbs.basic.pojo.po.AreaPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AreaRepositoryImpl implements AreaRepository {
@Autowired
private AreaMapper areaMapper;
    @Override
    public List<AreaPO> areaList(Integer parentId) {
        QueryWrapper<AreaPO> qu = new QueryWrapper<>();
        if(parentId==null){
            qu.eq("depth",1);
        }else {
            qu.eq("parent_id",parentId);

        }
        return areaMapper.selectList(qu);
    }

    @Override
    public List<AreaPO> areaAllList() {
        QueryWrapper<AreaPO> queryWrapper = new QueryWrapper<>();
        return areaMapper.selectList(queryWrapper);
    }
    
    @Override
    public List<AreaPO> cityList(AreaParam param) {
        // 修复JSON解析错误，重新实现cityList方法
        QueryWrapper<AreaPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("depth", param.getDepth()); // depth=2表示市级别
        return areaMapper.selectList(queryWrapper);
    }
}
